<?php

//淘宝开放平台
class BPlugin_taobaoopen extends BPlugin
{
    //签名函数
    function createSign ($paramArr, $appSecret) {
        $sign = $appSecret;
        ksort($paramArr);
        foreach ($paramArr as $key => $val) {
           if ($key !='' && $val !='') {
               $sign .= $key.$val;
           }
        }
        $sign = strtoupper(md5($sign.$appSecret));
        return $sign;
    }
    //urlencode并转换成字符串
    function createStrParam ($paramArr) {
        $strParam = '';
        foreach ($paramArr as $key => $val) {
           if ($key != '' && $val !='') {
               $strParam .= $key.'='.urlencode($val).'&';
           }
        }
        return $strParam;
    }
    //获取数据
    function get_content($url, $data = array(), $timeout = 5) {
        /*
        if(false && function_exists('file_get_contents')) {
            $file_contents = file_get_contents($url);
        } else {
        */
            $ch = curl_init();
            curl_setopt ($ch, CURLOPT_URL, $url);
            curl_setopt ($ch, CURLOPT_HEADER, false);
            curl_setopt ($ch, CURLOPT_POST, 1);
            $data && curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            $file_contents = curl_exec($ch);
            curl_close($ch);
        //}
        return $file_contents;
    }

    function getXmlData ($strXml) {
        $pos = strpos($strXml, 'xml');
        if ($pos) {
            $xmlCode=simplexml_load_string($strXml,'SimpleXMLElement', LIBXML_NOCDATA);
            $arrayCode=$this->get_object_vars_final($xmlCode);
            return $arrayCode ;
        } else {
            return '';
        }
    }
    function get_object_vars_final($obj){
        if(is_object($obj)){
            $obj=get_object_vars($obj);
        }
        if(is_array($obj)){
            foreach ($obj as $key=>$value){
                $obj[$key]=$this->get_object_vars_final($value);
            }
        }
        return $obj;
    }

}

?>
